<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<?php
     $idPro = $_GET['pro_id'];
?>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="view/jquery/jquery.ad-gallery.css">
  <link rel="stylesheet" type="text/css" href="view/css/style.css">
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script type="text/javascript" src="view/jquery/jquery.ad-gallery.js"></script>
  <script type="text/javascript" src="view/js/js.js"></script>
  <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
  <script type="text/javascript">
  $(function() {
    /*$('img.image1').data('ad-desc', 'Whoa! This description is set through elm.data("ad-desc") instead of using the longdesc attribute.<br>And it contains <strong>H</strong>ow <strong>T</strong>o <strong>M</strong>eet <strong>L</strong>adies... <em>What?</em> That aint what HTML stands for? Man...');
    $('img.image1').data('ad-title', 'Title through $.data');
    $('img.image4').data('ad-desc', 'This image is wider than the wrapper, so it has been scaled down');
    $('img.image5').data('ad-desc', 'This image is higher than the wrapper, so it has been scaled down');*/
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
        galleries[0].slideshow.toggle();
        return false;
      }
    );
    $('#toggle-description').click(
      function() {
        if(!galleries[0].settings.description_wrapper) {
          galleries[0].settings.description_wrapper = $('#descriptions');
        } else {
          galleries[0].settings.description_wrapper = false;
        }
        return false;
      }
    );
    var firt_select = $('ul.ad-thumb-list li');
      a(firt_select);
      b(firt_select);
      c(firt_select);
  });
        //get product
	function a(obj) {		 
            var id = <?php  echo $_GET['pro_id'];?>;
            $.getJSON("controller/product/ajax_request.php?idProduct="+id,function(data){
                $("#product_detail").html('$' + data.price_bid );
                $('#pro_id').val(id);
                $('#price_bid').val(data.price_bid);
                $("#pro_name").html(data.pro_name);
                $("#pro_desc").html(data.pro_desc);
                $("#value").html('Value: '+data.pro_prince);
                $("#bid_price").html(data.price_bid);     
                var a =  data.price_bid;
                var b = data.pro_prince;
                var c = b - a;
                var d = c*100/b
                $("#saving").html('Saving: '+d+'%');

            });   
            return false;
        }
	  //get value bid history
	  function b(obj) {
            //var id = $(obj).parent().find('input').val();
            var id=<?php  echo $_GET['pro_id'];?>;
            $.getJSON("controller/product/ajax_bid.php?idProduct="+id,function(data){
                var respondHtml = "";
                for (var i = 0; i < data.length; i++) { 
                    var item = data[i];
                    respondHtml += "<tr><td>" + item['bid_price'] + "</td>" + "<td>" +  item['email'] + "</td></tr>";
                } 
                $('#bidhistory').html("<table cellspacing='0' class='broom_table' border='1'><tr><td>Bid</td><td>Bidder</td></tr>" + respondHtml + "</table>" );
                $('#total_bid').html('<br/>Total: ' + data.length);
                $('#totalbid').val(data.length);
            });   
                return false;
        }
        //member won
        function c(obj) {
            //var id = $(obj).parent().find('input').val();
            var id=<?php  echo $_GET['pro_id'];?>;
            $.getJSON("controller/product/memWon.php?idProduct="+id,function(data){
                $('#sold_date').html('Sold date: '+data.sold_date);
                $('#soldfor').html('Sold for: '+data.soldfor);
                $('#sold-mem').html('Sold member: '+data.email);
            });   
                return false;
        }

  </script>

</head>
<?php
	require_once 'model/global.inc.php';  
	include("model/database.php");
	include("model/products.php");
?>
<body>
    <div class="main">
  <div id="container">
      <div id="pro_name"></div>

    <div id="gallery" class="ad-gallery">
        
      <div class="ad-image-wrapper">
      </div>
      <div class="ad-controls">
      </div>
      <div class="ad-nav">
        <div class="ad-thumbs">
			<ul class="ad-thumb-list">
		<?php
			$tbl = new products();
			$row = $tbl->get_product_image_by_proid($idPro);
			foreach($row as $row_pro => $key)
			{
        ?>
				<li>
					<?php
						if($key != '')
						{
					?>
							<a href="<?php echo "images-products/$key" ?>">
							<img src="<?php echo "images-products/thumbnail/$key" ?>" >
							</a> 
                    <?php } ?>
				</li>  
			<?php }?>	
			</ul>
        </div>
      </div>       
    </div>
      <?php
      if(isset($_SESSION['logged_in'])){
         $user = unserialize($_SESSION['user']);
         $memid = $user->memid;
      	 }
					else
					$memid = null;
      ?>
      <div class="product" style="float: left; width: 200px; padding-left: 10px; text-align: center;">
            <div id="product_detail">$0</div>

	<div id="avarta">
            <?php
                $userTool = new UserTools();
				$avarta = $userTool->getAvartaByMemId($memid);
                $avar = $avarta["avarta"];
           ?>
                <img src="<?php echo "view/avarta/$avar" ?>" width="100px" >
        </div>
                               <form id="frm1" name="frm1" method="post" action="" ";>
                                   <input type="hidden" value="" name="pro_id" id="pro_id" />
                                   <input type="hidden" value="" name="price_bid" id="price_bid" />
                                   <input type="hidden" value="<?php echo $memid ?>" name="memid" id="memid" />
                                   <input type="hidden" value="" id="totalbid"/>
                                   
                               </form>
        <div id="mem-won">
            <div id="sold-mem"></div>
            <div id="soldfor"></div>
            <div id="saving"></div>
            <div id="value"></div>
            <div id="sold_date"></div>
        </div>
     </div>
        <!--Hien thi bid history -->
        <div class="bid" style="float: left; width: 300px; padding-left: 10px; text-align: center;">
            <div id="bidhistory"></div>
            <div id="total_bid"></div>
        </div>
        <!--End hien thi bid history -->
        <div id="lblMessage"></div>
  
  </div>
    <div id="pro_desc"></div>
    </div>
<script type="text/javascript">
    $(document).ready(function(){
        $("#frm1").validate({			
            submitHandler: function(form) {
                    // do other stuff for a valid form
                    $.post('controller/product/submit.php', $("#frm1").serialize(), function(data) {
                        $('#lblMessage').html(data);

                    });
                    a('');
                    b('');       

            }

        });

    });
</script>    
</body>
</html>